import * as dto from './DTO';
import {request, handleFetchResultNotification, REQUEST_TYPE} from '../utils';
import stringify from 'Shared/utils/stringify';
import {formatMessage} from './intl';

const baseUrl = '/parts/api/v1';

const initDesc = formatMessage({
    id: 'api.message.initDesc',
    defaultMessage: '初始化界面'
});
const getListDesc = formatMessage({
    id: 'api.message.getListDesc',
    defaultMessage: '查询备件价格'
});
const exportDataDesc = formatMessage({
    id: 'api.message.exportDataDesc',
    defaultMessage: '导出备件价格'
});
//初始化
export const getInitData = () => request(`${baseUrl}/ui/partSalesPrice/init`, null, dto.InitDataStruct)
    .then(handleFetchResultNotification(REQUEST_TYPE.initQuery, initDesc));
// 查询订单列表
export const getList = data => request(`${baseUrl}/partSalesPrices/forCurrentUser`, {
    method: 'POST',
    headers: {'Content-Type': 'application/json'},
    body: JSON.stringify(data)
}).then(handleFetchResultNotification(REQUEST_TYPE.query, getListDesc));

//导出信息
export const exportData = data => request(`${baseUrl}/partSalesPrices/forCurrentUser`, {
    method: 'POST',
    headers: {'Content-Type': 'application/json'},
    body: JSON.stringify(data)
}).then(handleFetchResultNotification(REQUEST_TYPE.submit, exportDataDesc));
